package com.example.demomybatis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.demomybatis.entity.TicketModelType;
import com.example.demomybatis.mapper.TicketModelTypeMapper;
import com.example.demomybatis.model.TicketModelTypeVo;
import com.example.demomybatis.model.TicketQuery;
import com.example.demomybatis.service.ITicketModelTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 模型名称和服务类型关系表 服务实现类
 * </p>
 *
 * @author zhaoheng
 * @since 2023-08-07
 */
@Service
public class TicketModelTypeServiceImpl extends ServiceImpl<TicketModelTypeMapper, TicketModelType> implements ITicketModelTypeService {
    @Resource
    TicketModelTypeMapper ticketModelTypeMapper;
    @Override
    public List<TicketModelType> complexQuery() {
        LambdaQueryWrapper<TicketModelType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TicketModelType::getServiceType, "资源池")
                .and(wrap -> {
                    wrap.eq(TicketModelType::getTicketModelName, "111").or().eq(TicketModelType::getId, 2);
                });

        return this.list(queryWrapper);
    }

    @Override
    public List<TicketModelType> sqlQuery() {
        LambdaQueryWrapper<TicketModelType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TicketModelType::getServiceType, "资源池")
                .and(wrap -> {
                    wrap.eq(TicketModelType::getTicketModelName, "111").or().eq(TicketModelType::getId, 2);
                });
        String sqlSegment = queryWrapper.getSqlSegment();
        System.out.println(sqlSegment);
        String sqlSelect = queryWrapper.getSqlSelect();
        System.out.println(sqlSelect);
        return null;
    }

    @Override
    public List<TicketModelType> queryByCondition(TicketQuery ticketQuery) {
        return ticketModelTypeMapper.queryByCondition(ticketQuery);
    }

    @Override
    public List<TicketModelTypeVo> queryVoByCondition(TicketQuery ticketQuery) {
        return ticketModelTypeMapper.queryVoByCondition(ticketQuery);
    }

    @Override
    public List<TicketModelType> jointSql() {
        String sqlSegment = "id = 1";

        String sqlSegment2 = "ticket_model_name like '%IP%'";
        return ticketModelTypeMapper.jointSql(sqlSegment, sqlSegment2);
    }
}
